﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HerbertDotNet
{
    public static class HerbertHelper
    {
        public const string ProcedureNames = "abcdefghijkmnopqtuvwxyz";
        public const string ParameterNames = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        internal static string GetInstructionText(HInstruction instruction)
        {
            // Check if instruction is number.
            if ((instruction & HInstruction.NumberBase) != 0)
            {
                return string.Format("{0}: {1}", HInstruction.NumberBase.ToString(),
                    (byte)(instruction ^ HInstruction.NumberBase));
            }

            // Check if instruction is procedure name.
            if ((instruction & HInstruction.ProcedureNameBase) != 0)
            {
                return string.Format("{0}: {1}", HInstruction.ProcedureNameBase.ToString(), 
                    ProcedureNames[(int)(instruction ^ HInstruction.ProcedureNameBase)]);
            }

            // Check if instruction is parameter name.
            if ((instruction & HInstruction.ParameterNameBase) != 0)
            {
                return string.Format("{0}: {1}", HInstruction.ParameterNameBase.ToString(),
                    ParameterNames[(int)(instruction ^ HInstruction.ParameterNameBase)]);
            }

            return instruction.ToString();
        }
    }
}
